define(function(require, exports){
	var pubjs = require('pubjs');
	var $ = require('jquery');
	var grid  = require('@base/highGrid');
	// var tip  = require('@base/tip');
	var util = require('util');

	// 资质管理审核状态列表
	var Base = grid.base.extend({
		init: function(config){
			var metrics = [];
			var map = pubjs.config('channelMap');
			util.each(pubjs.config('aptitude_group'), function(exchange_id) {
				metrics.push({
					name: 'info' + exchange_id,
					render: 'renderStatus',
					align: 'center',
					param: exchange_id,
					text: map[exchange_id] || LANG('未知渠道')
				});
			});

			config = pubjs.conf(config, {
					url: '',
					reqType: 'websocket',
					hasTab: false,
					hasAmount: false,
					hasSearch: false,
					hasSwitch: false,
					hasExport: false,
					hasMenu: false,
					hasRefresh: false,
					hasSubGrid: true,
					hasSelect: false,
					hasPager: true,
					auto_load: true,
					cols: [
						{type: 'id'}
					],
					metrics: metrics
				}
			);
			this.Super('init', arguments);
			this.uiProxy(this.getDOM(),'.rejectReason','mouseenter mouseleave','eventRejectReason');
		},
		// 审核栏渲染函数
		renderStatus: function(i,val,row, col) {
			var v = util.find(val, col.param, "ExchangeId");
			if(v && !v.IsDeleted){
				switch(v.Status){
					case 2 :
						return '<div title="'+LANG("部分通过")+'"class="icon done"></div>';
					case 1 :
						return '<div title="'+LANG("通过")+'" class="icon done"></div>';
					case 0 :
						return '<div title="'+LANG("待审核")+'" class="icon wait"></div>';
					case -2 :
						return '<div title="'+LANG("审核中")+'" class="icon ing"></div>';
					case -1 :
						var html = '<div title="'+LANG("未通过")+'" class="icon rejectReason ';
						html += (v.RejectReason && v.RejectReason.indexOf('系统判断：') === 0) ? 'sys' : 'err';
						html += '" data-info="'+util.html(v.RejectReason)+'"/>';
						return html;
				}
			}else{
				return null;
			}
		},
		/**
		 * 鼠标事件-展示素材审核失败的原因
		 */
		eventRejectReason: function(evt, elm){
			var tip  = this.get('rejectReasonTip');
			switch (evt.type){
				case 'mouseenter':
					elm = $(elm);
					var rejectReason = elm.attr("data-info");

					if (!tip){
						tip = this.create('rejectReasonTip', tip.base, {
							'width': 300,
							'pos': 'ml',
							'anchor': elm,
							'autoHide': 1,
							'outerHide': 1
						});
						this.$tipContent = $('<div class="con"/>').appendTo(tip.body);
					}else{
						tip.reload({anchor: elm});
					}
					this.$tipContent.text(rejectReason);
					tip.show();
				break;
				case 'mouseleave':
					if (tip){ tip.delayHide(500); }
				break;
			}
			return false;
		}
	})
	exports.base = Base;
});